package org.repo.ant.tasks;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.Javac;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.repo.ant.util.Util;
import org.repo.ant.util.ValidationUtil;

public class RepoJavac extends Javac{
	
	protected String repo;
	protected String repoBase;
	protected String repoDirectory;
	
	protected String repoIncludesFile;
	protected String repoExcludesFile;

	@Override
	public void execute() throws BuildException {
		try{
			ValidationUtil.RepoJavac.validateParams(repo, repoBase, repoDirectory, repoIncludesFile, repoExcludesFile);
			
			FileSet repoJarFileSet = Util.setupRepoJarFileSet(getProject(), repo, repoBase, repoDirectory, repoIncludesFile, repoExcludesFile);
			
			Path path = new Path(getProject());
			path.addFileset(repoJarFileSet);
			Path existingClasspath = getClasspath()!=null?getClasspath():new Path(getProject());
			existingClasspath.add(path);
			setClasspath(existingClasspath);
			
			super.execute();
		}
		catch(BuildException bE){
			throw bE;
		}
		catch(Throwable t){
			t.printStackTrace();
			throw new BuildException(t);
		}		
	}

	public String getRepo() {
		return repo;
	}

	public void setRepo(String repo) {
		this.repo = repo;
	}

	public String getRepoBase() {
		return repoBase;
	}

	public void setRepoBase(String repoBase) {
		this.repoBase = repoBase;
	}

	public String getRepoDirectory() {
		return repoDirectory;
	}

	public void setRepoDirectory(String repoDirectory) {
		this.repoDirectory = repoDirectory;
	}

	public String getRepoIncludesFile() {
		return repoIncludesFile;
	}

	public void setRepoIncludesFile(String repoIncludesFile) {
		this.repoIncludesFile = repoIncludesFile;
	}

	public String getRepoExcludesFile() {
		return repoExcludesFile;
	}

	public void setRepoExcludesFile(String repoExcludesFile) {
		this.repoExcludesFile = repoExcludesFile;
	}

	
}
